import 'package:flutter/material.dart';
import './RatingStar.dart';

class RatingBar extends StatefulWidget {
  final int maxRate;
  final int countRate;
  final Color color;
  final double size;
  final double spacing;

  RatingBar({this.maxRate, this.countRate, this.color, this.size, this.spacing});

  @override
  _RatingBarState createState() => new _RatingBarState();
}

class _RatingBarState extends State<RatingBar> {
  @override
    void initState() {
      super.initState();
    }

  @override
  Widget build(BuildContext context) {
    List<Widget> children = new List(widget.maxRate ?? 5);
    int index = 0;
    int count = widget.countRate ?? 0;
    for(int i=0; i<count; i++) {
      children[index++] = new RatingStart(
        icon: Icons.star,
        color: widget.color ?? Colors.orangeAccent,
        size: widget.size ?? 45.0,
        spacing: widget.spacing ?? 5.0,
      );
    }
    
    int max = widget.maxRate ?? 5;
    for(int i=count; i<max; i++) {
      children[index++] = new RatingStart(
        icon: Icons.star_border,
        color: widget.color ?? Colors.orangeAccent,
        size: widget.size ?? 45.0,
        spacing: widget.spacing ?? 5.0,
      );
    }

    return new Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: children,
    );
  }
}
